package com.myrpc.test.loadbean;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.SynchronousQueue;

public class SynchronousqueueTs implements Runnable{
	
	static ConcurrentHashMap<String, SynchronousQueue<Object>> queueMap = new ConcurrentHashMap<String, SynchronousQueue<Object>>();
	static String key = "requestId";
	public static void main(String[] args) throws Exception {
		
		SynchronousQueue queue = sendMsg();
		
		new Thread(new SynchronousqueueTs()).start();
		
		Object object = queue.take();
		
		System.out.println("收到的结果：" + object);	
	}
	
	
	public static SynchronousQueue sendMsg() {
		SynchronousQueue queue = new SynchronousQueue<Object>();
		queueMap.put(key, queue);
		System.out.println("send msg ...");
		return queue;
		
	}
	
	public void messageReceived() throws InterruptedException {
		String result = "result_MSG"; 
		
		SynchronousQueue<Object> queue = queueMap.get(key);
		queue.put(result);
		
	}


	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			messageReceived();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	


}
